<#include "/common/dhtml_gantt.html">
<style>
.weekend{background: #ccc !important;}
.noticetask{background: red !important; font-weight: bold;}
/* .warningtask{background: orange !important;} */
.noticetask .gantt_task_progress{
    background:#CCC333;
}
</style>
<h1 align="center">环线一期站后工程进度计划横道图-${station_name!'站'}</h1>
<span>图表导出：</span>
<select id="export" style='margin: 10px;' onchange='exportTo()'>
	<option>导出到...</option>
	<option value="pdf">PDF</option>
	<option value="png">PNG</option>
	<option value="excel">Excell</option>
	<option value="ical">iCal</option>
</select>
<div id="gantt_here" style="width: 1920px; height: 500px;"></div>
<iframe src="${ctx}/gantt/fooeterList" style="width: 100%; height:300px;border: none" id="ifrmid"></iframe>
<script type="text/javascript">
	// add month scale
	gantt.config.scale_unit = "day"; //第一个时间尺度，即X轴的单位，包括："minute", "hour", "day", "week", "month", "year"
	gantt.config.date_scale = "%M%d日";	
	gantt.templates.date_scale = function(date) {
		return gantt.date.date_to_str(gantt.config.date_scale)(date);
	};
	gantt.config.subscales = [ //第二个时间尺度单位
	{
		unit : "year",
		step : 1,
		date : "%Y"
	}, {
		unit : "day",
		step : 1,
		date : "%D"
	} ];
	gantt.config.scale_height = 3 * 28; //设置时间尺度和Grid树的高度
	gantt.config.work_time = true;
	gantt.config.correct_work_time = true;
	
	gantt.templates.scale_cell_class = function(date){
	    if(date.getDay()==0||date.getDay()==6){
	        return "weekend";
	    }
	};
	gantt.templates.task_cell_class = function(item,date){
	    if(date.getDay()==0||date.getDay()==6){ 
	        return "weekend" ;
	    }
	};	
	gantt.templates.grid_row_class = function(start, end, task){
	   	if(task.status==-1){
	   		return "noticetask";
	   	}
	   /* 	else if(task.status==1){
	   		return "warningtask";
	   	} */
	   	else{
	   		return "";
	   	}
	};
	//横道图行颜色设置
	/* gantt.templates.task_row_class = function(start, end, task){
	   	if(task.status==-1){
	   		return "noticetask";
	   	}
	   	else if(task.status==1){
	   		return "warningtask";
	   	}
	   	else{
	   		return "";
	   	}
	}; */
	gantt.templates.task_class = function(start, end, task){
		if(task.status==-1){
	   		return "noticetask";
	   	}
	   	/* else if(task.status==1){
	   		return "warningtask";
	   	} */
	   	else{
	   		return "";
	   	}
	};
	
	/* 
	// configure milestone description
	gantt.templates.rightside_text = function(start, end, task) {//进度条右侧的提示文字
		if (task.type == gantt.config.types.milestone) {
			return task.text;
		}
		return "";
	}; */
	//显示完成百分比
	gantt.templates.progress_text = function(start, end, task) {
		return "任务进度："+task.progress * 100 + "%";
	};
	//左侧显示数据列
	gantt.config.columns = [ 
	                         
	 {
		name:"wbs",	 
	  	label:"WBS", 
	  	width:60, 	  
	    template:gantt.getWBSCode 	 
	}, {
		name : "text",
		label : "任务名",
		tree : true,		
		width : 250,
	}, {
		name : "start_date",
		label : "计划开工时间",
		align : "center",
		width : 100
	}, {
		name : "end_date",
		label : "计划完工时间",
		align : "center",
		width : 100
	}, {
		name : "p_duration",
		label : "计划工期",
		align : "center",
		width : 80,
		template:function(obj){
			if(obj.p_duration==null){
				return "";
			}
			else{
				return obj.p_duration;
			}
        }
	} , {
		name : "real_sdate",
		label : "实际开工时间",
		align : "center",		
		width : 100,
		template:function(obj){
			if(obj.real_sdate==null){
				return "";
			}
			else{
				return obj.real_sdate;
			}
        }		
	}, {
		name : "real_edate",
		label : "实际完工时间",
		align : "center",
		width : 100,
		template:function(obj){
			if(obj.real_edate==null){
				return "";
			}
			else{
				return obj.real_edate;
			}
        }
	}, {
		name : "r_duration",
		label : "实际工期",
		align : "center",
		width : 80,
		template:function(obj){
			if(obj.r_duration==null){
				return "";
			}
			else{
				return obj.r_duration;
			}
        }
	},{
		name : "status",
		label : "偏离状态",
		align : "center",
		width : 80, 
		template:function(obj){
			if(obj.status==-1){
				return "负偏离"
			}
			else if(obj.status==0){
				return "正常进度"
			}
			else if(obj.status==1){
				return "正偏离"
			}else{
				return "";
			}
        }
	}/* , {
			name : "add",
			label : "",
			align : "center",
			width : 60
		} */
	];
	// 弹出编辑对话框
	gantt.config.lightbox.sections = [//弹出对话框设置
	{
		name : "description",
		height : 70,
		map_to : "text",
		type : "textarea",
		focus : true
	}, {
		name : "type",
		type : "typeselect",
		map_to : "type"
	}, {
		name : "time",
		height : 72,
		type : "duration",
		map_to : "auto"
	} ];

	gantt.config.xml_date = "%Y-%m-%d %H:%i:%s"; // XML中的日期格式 
	// enable dataProcessor
	/*
	var dp = new dataProcessor("/Home/Save");//dhtmlxGantt保存变化，包括添加、更新、删除
	dp.init(gantt); */
	gantt.config.readonly = true;
	gantt.init("gantt_here");//初始化dhtmlxGantt,gantt_here为视图中div的id
	gantt
			.load("${ctx}/gantt/getOneSchedule?station_id=${stationId!''}",
					"json");//加载数据

	gantt.attachEvent("onTaskSelected", function(id, item) {
		var src = "${ctx}/gantt/fooeterList?task_id=" + id
				+ "&station_id=${stationId!''}";
		document.getElementById('ifrmid').src = src;
	});
	//新增任务时，执行相关操作
	gantt.createTask = function(t, e, n) {
		if (
				t = t || {},
				gantt.defined(t.id) || (t.id = gantt.uid()),
				t.start_date || (t.start_date = gantt._default_task_date(t, e)),
				void 0 === t.text && (t.text = gantt.locale.labels.new_task),
				void 0 === t.duration && (t.duration = 1), e) {
			this.setParent(t, e);
			var a = this.getTask(e);
			dhtmlxGanttParentId = a.id, dhtmlxGanttText = a.text,
					dhtmlxGanttplanFileId = a.planFileId, a.$open = !0
		}
		customAlert(dhtmlxGanttText, dhtmlxGanttParentId, dhtmlxGanttplanFileId);
		return null;
		/*this.callEvent("onTaskCreated",[t])?(this.config.details_on_create?(t.$new=!0,this._pull[t.id]=this._init_task(t),
		this._add_branch(t,n),t.$level=this.calculateTaskLevel(t),this.selectTask(t.id),this.refreshData(),this.showLightbox(t.id)):this.addTask(t,e,n)&&(this.showTask(t.id),this.selectTask(t.id)),t.id):null */
	};
	function customAlert(a, b, c) {
		alert(a + b + c);
	};
	//导出图标到?
	var exportTo = function() {
		var output = document.getElementById("export").value;
		switch (output) {
		case "pdf":
			gantt.exportToPDF();
			break;
		case "png":
			gantt.exportToPNG();
			break;
		case "excel":
			gantt.exportToExcel();
			break;
		case "ical":
			gantt.exportToICal();
			break;
		default:
			alert("Wrong file format");
		}
	};
</script>
</body>
</html>